package com.effectiv.gooruda.rest.api.service;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import com.effectiv.gooruda.rest.api.domain.Image;
import com.effectiv.gooruda.rest.api.operation.ImageOperations;
import com.effectiv.gooruda.security.rest.RESTSecurityUtil;

@Component
public class ImageService  implements ImageOperations {

	@Override
	public Image changeFormat(String name, String newFormat,
			MultipartFile multipartFile) {
		
		String fileName = name + "_" + RESTSecurityUtil.getAppId()  +"." + newFormat;
		
		Image image = null;
		
		try {
			ImageIO.write(ImageIO.read(multipartFile.getInputStream()), newFormat, new File(fileName));
			
			//Save image details
			
		} catch (IOException e) {
			//TODO - raise error
			
		}

		
		return image;
	}

}
